package LeetCode.month02.day55;
import java.util.*;
public class No199 {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if(root==null) return res;
        Deque<TreeNode> deque = new ArrayDeque<>();
        deque.add(root);
        while(!deque.isEmpty()){
            int n = deque.size();
            for (int i = 0; i < n; i++) {
                TreeNode curr = deque.poll();
                if(i==n-1){
                    res.add(curr.val);
                }
                if(curr.left!=null) deque.add(curr.left);
                if(curr.right!=null) deque.add(curr.right);
            }
        }
        return res;
    }
}
